/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pos.Driving.Train;

/**
 *
 * @author Administrator
 */
public class ATP {
    private Train myTrain;
    private int ATS_Level;
    private double speedSignal;
    private double overspeedTime;
    
    public ATP(Train myTrain, int ATS_Level) {
        this.myTrain = myTrain;
        this.ATS_Level = ATS_Level;
        speedSignal=77;
        overspeedTime=0;
    }

    public void setSpeedSignal(double speedSignal) {
        this.speedSignal = speedSignal;
    }

    public void setATS_Level(int ATS_Level) {
        this.ATS_Level = ATS_Level;
    }

    public double getSpeedSignal() {
        return speedSignal;
    }
    
    public double getSpeedLimit(){
        switch (myTrain.getCurrentMode()){
            case Train.MODE_OFF:
                return 0;
            case Train.MODE_ATO:
                return speedSignal;
            case Train.MODE_ATPFORWARD:
                return speedSignal;
            case Train.MODE_ATPBACKWARD:
                return 20;
            case Train.MODE_WM:
                return 5;
            default:
                return 0;
        }
    }
    
    public void checkOverSpeed(double currentSpeed,double step){
        if (Math.abs(currentSpeed)-0.5 > Math.abs(getSpeedLimit()))
            overspeedTime += step;
        else
            overspeedTime = 0;
        if (overspeedTime>3)
            myTrain.EB();
    }
}
